#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''=================================================
@Project -> File   ：js逆向 -> 易车网
@IDE    ：PyCharm
@Author ：王启俊
@Date   ：2024-04-11 19:53
@Desc   ：
=================================================='''
import time

import requests
import json
import execjs

"""
cid: 508
params:{"cityId":"802","serialId":"10628"}


动态的参数
  "X-Sign": "26e29faf488da2d965b110b2b9f33b43",
  "X-Timestamp": "1712836601894",
  
  Cookie
  Hm_lpvt_610fee5a506c80c9e1a46aa9a2de2e44
  
  

  密钥    
  f48aa2d0-31e0-42a6-a7a0-64ba148262f0
  
  用来加密参数
  "cid=508&param={}19DDD1FBDFF065D3A4DA777D2D7A81EC1712841626356"
"""

if __name__ == '__main__':
    url = "https://mhapi.yiche.com/hcar/h_car/api/v1/param/get_param_details?cid=508&param=%7B%22cityId%22%3A%22802%22%2C%22serialId%22%3A%2210628%22%7D"
    timer = int(time.time() * 1000)
    params = {
        "cid":"508",
        "serialId":'{"cityId":"802","serialId":"10628"}'
    }
    with open('2.js', 'r', encoding='utf-8') as f:
        jx = execjs.compile(f.read())
        sign = jx.call('get_sign',
                       "cid=508&param={\"cityId\":\"802\",\"serialId\":\"10628\"}19DDD1FBDFF065D3A4DA777D2D7A81EC" + str(timer))

        headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
            "Cookie": f"CIGDCID=138ef0fb4d5b3563ba077b8540149501; G_CIGDCID=138ef0fb4d5b3563ba077b8540149501; auto_id=6c9a1f5383083317acf0cbb7b31e2605; CIGUID=d72dd00e-8071-4f38-8bb5-7ac93652ae0d; selectcity=469002; selectcityid=802; selectcityName=%E7%90%BC%E6%B5%B7; UserGuid=d72dd00e-8071-4f38-8bb5-7ac93652ae0d; csids=10628; isWebP=true; locatecity=469002; bitauto_ipregion=2409%3A8a5e%3Aa51%3Aefb0%3Ae1e2%3Ae1b2%3Ac20d%3Ad314%3A%E6%B5%B7%E5%8D%97%E7%9C%81%E7%90%BC%E6%B5%B7%E5%B8%82%3B802%2C%E7%90%BC%E6%B5%B7%E5%B8%82%2Cqionghai; pageCount=4; Hm_lvt_610fee5a506c80c9e1a46aa9a2de2e44=1712668351,1712836557; Hm_lpvt_610fee5a506c80c9e1a46aa9a2de2e44={int(time.time())}",
            "X-Sign": sign,
            "X-Timestamp": str(timer),
            "X-User-Guid": "d72dd00e-8071-4f38-8bb5-7ac93652ae0d",
            "X-Platform": "pc",
            "X-Ip-Address": "2409:8a5e:a51:efb0:e1e2:e1b2:c20d:d314",
            "X-City-Id": "802",
            "Referer": "https://car.yiche.com/xiaomisu7/peizhi/",
            "Cid": "508"

        }
        resu = requests.get(url, headers=headers)
        for i in resu.json().get('data').get('list'):
            print(i)
